package com.app.toknow.Fragment;

import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.app.toknow.R;

import com.app.toknow.Adapter.MainMenuListAdapter;
import com.app.toknow.Common.SharedPreferencesUtil;
import com.app.toknow.Entity.MainMenuItemInfo;

import java.util.LinkedList;

/**
 */
public class LeftMenuFragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private ListView listView;
    private TextView tvNameNike;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View contentView = inflater.inflate(R.layout.fragment_left_menu,container,false);
        int id = Integer.parseInt(SharedPreferencesUtil.get(getActivity().getApplicationContext(), "LoginApp_UserID",-1).toString());
        tvNameNike = (TextView) contentView.findViewById(R.id.main_left_ment_nameNike);
        if(id<0){
            tvNameNike.setText("未登录");
        }
        else{
            //通过ID获取用户信息
        }
        // 获取 fragment 中的控件对象
        listView = (ListView) contentView.findViewById(R.id.main_left_menu_listview);
        String[] contentArray = this.getResources().getStringArray(R.array.array_main_menu_content);

        TypedArray iconArray = this.getResources().obtainTypedArray(R.array.array_main_menu_iconid);

        LinkedList<MainMenuItemInfo> itemList= new LinkedList<MainMenuItemInfo>();
        for (int i=0;i<contentArray.length;i++)
        {
            MainMenuItemInfo item = new MainMenuItemInfo();
            item.setIconRes(iconArray.getDrawable(i));
            item.setContent(contentArray[i]);
            itemList.add(item);
        }
        MainMenuListAdapter adapter = new MainMenuListAdapter(getActivity().getApplicationContext(),itemList);
        listView.setAdapter(adapter);
        return contentView;
    }
}
